package com.mike.employment.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mike.employment.base.BaseDao;
import com.mike.employment.base.BaseServiceImpl;
import com.mike.employment.dao.AccountDao;
import com.mike.employment.po.Account;
import com.mike.employment.service.AccountService;
import com.mike.employment.vo.LoginVo;

import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;

@Service
public class AccountServiceImpl extends BaseServiceImpl<Account> implements AccountService{
	
	@Autowired
	private AccountDao accountDao;
	@PersistenceContext
	private EntityManager entityManager;
	
	@Override
	public BaseDao<Account> getRepository() {
		return accountDao;
	}

	@Override
	public EntityManager getEntity() {
		return entityManager;
	}
	
	
	@Override
	public Account register(LoginVo vo) {
		Account account = new Account();
		account.setName(vo.getName());
		account.setPwd(vo.getPwd());
		return accountDao.save(account);
	}

	@Override
	public Account login(LoginVo vo) {
	    List<Account> list = accountDao.findByNameAndPwdAndStatus(vo.getName(), vo.getPwd(), 0);
	    if(list!= null && list.size() >0) {
	    	return list.get(0);
	    }
		return null;
	}

}
